//
//  BCVCDataNetPro.swift
//  NewXueBa
//
//  Created by Shine on 2019/6/13.
//  Copyright © 2019 jmxQAQ. All rights reserved.
//

import Foundation

protocol BCVCDataNetPro: UIViewController {
}

extension BCVCDataNetPro {
    
    func loadBCProViewInVC(image: UIImage?, alertText: String, frame: CGRect) -> BCProtocolView {
        
        let proView = BCProtocolView()
        proView.backgroundColor = UIColor.hex(hexString: "#f8f8f8")
        proView.frame = frame
        print(proView.frame)
        self.view.addSubview(proView)
        
        let imageV = UIImageView()
        imageV.bounds = CGRect(x: 0, y: 0, width: 187*2/3, height: 124*2/3)
        imageV.center = CGPoint(x: frame.size.width/2, y: frame.size.height/2 - 60)
        imageV.image = image
        proView.addSubview(imageV)
        proView.proImageV = imageV
        
        let alertLabel = UILabel()
        alertLabel.textAlignment = .center
        alertLabel.textColor = UIColor.hex(hexString: "#2E3D4B")
        alertLabel.font = UIFont.systemFont(ofSize: 15)
        let y = imageV.frame.maxY + 10
        alertLabel.frame = CGRect(x: 0, y: y, width: frame.size.width, height: 25)
        alertLabel.text = alertText
        proView.addSubview(alertLabel)
        proView.proLabel = alertLabel
        
        return proView
    }
    
    // 无网络的情况
    func loadBCNoNetProViewInVC(frame: CGRect) -> BCProtocolView {
        
        let proView = BCProtocolView()
        proView.backgroundColor = UIColor.hex(hexString: "#f8f8f8")
        proView.frame = frame
        print(proView.frame)
        self.view.addSubview(proView)
        
        let imageV = UIImageView()
        imageV.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
        imageV.center = CGPoint(x: frame.size.width/2, y: frame.size.height/2 - 50)
        imageV.image = UIImage(named: "image_no_internet")
        proView.addSubview(imageV)
        
        let alertLabel = UILabel()
        alertLabel.textAlignment = .center
        alertLabel.textColor = UIColor.hex(hexString: "#7F899A")
        alertLabel.font = UIFont.systemFont(ofSize: 15)
        let y = imageV.frame.maxY
        alertLabel.frame = CGRect(x: 0, y: y, width: frame.size.width, height: 25)
        alertLabel.text = "网络断开，请检查网络是否正常"
        proView.addSubview(alertLabel)
        
        let refreshLabel = UILabel()
        refreshLabel.textAlignment = .center
        refreshLabel.textColor = UIColor.hex(hexString: "#1AA5FF")
        alertLabel.font = UIFont.systemFont(ofSize: 15)
        let refreshLabely = alertLabel.frame.maxY + 40
        refreshLabel.frame = CGRect(x: 0, y: refreshLabely, width: frame.size.width, height: 20)
        refreshLabel.text = "刷新"
        proView.addSubview(refreshLabel)
        
        let freshBtn = UIButton()
        freshBtn.frame = CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)
        proView.addSubview(freshBtn)
        proView.refreshBtn = freshBtn
        
        return proView
    }
    
    
}

class BCProtocolView: UIView {
    var proImageV: UIImageView?
    var proLabel: UILabel?
    var refreshBtn: UIButton?
}
